/**
 * @Title: HomeActivity.java
 * @Package com.sinoglobal.waitingMe.activity
 * @Description: TODO(用一句话描述该文件做什么)
 * @author hpq
 * @date 2015-8-30 上午11:55:09
 */

package com.sinoglobal.wallet.activity;

import java.math.BigDecimal;

import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.sinoglobal.wallet.R;
import com.sinoglobal.wallet.util.NetWorkUtil;

/**
 * @author clf
 * @createdate 2015-10-26现详情)
 */
public class W_WithDrawalRecordDetailActivity extends W_SinoBaseActivity {

	private TextView withDrawal_record_details_back,withDrawal_money_instrution,withDrawal_record_details_actual_money,withDrawal_record_details_bank_name,withDrawal_record_details_withdrawlmoney,withDrawal_record_details_state;
	private LinearLayout withDrawal_record_details_actual_money_layout;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.wallet_withdrawal_record_detail_layout);
		mTemplateTitleText.setText("提现详情");
		initView();
		if(getIntent()!=null){
	        String bankName = getIntent().getStringExtra("BankName");
	        String instrution = getIntent().getStringExtra("Instrution");
	        String money = getIntent().getStringExtra("Money");
	        String fees = getIntent().getStringExtra("Fees");
	        String state = getIntent().getStringExtra("State");
	    	if(fees==null){
	    		fees="1.0";//如果手续费是null就设置1元
    		}
	        if(state!=null){
	        	if("0".equals(state)){
	        		withDrawal_money_instrution.setVisibility(View.GONE);
	        		BigDecimal b= new BigDecimal(money);
		    		BigDecimal c= new BigDecimal(fees);
	        		/*
	        		Double 	actual_money=Double.valueOf(money)-Double.valueOf(fees);
	        		BigDecimal bd=new BigDecimal(actual_money);//提现1.2手续费1.0结果是0.1999999999999；避免double类型异常，用BigDecimal四舍五入；
	        		bd=bd.setScale(2, BigDecimal.ROUND_HALF_UP);
	        			withDrawal_record_details_actual_money.setText(bd+"元");
	        		*/
	        		withDrawal_record_details_actual_money_layout.setVisibility(View.VISIBLE);
	        		withDrawal_record_details_actual_money.setText(String.format("%.2f", b.subtract(c).doubleValue())+"元");
	        		withDrawal_record_details_withdrawlmoney.setText(Html.fromHtml("<font size=28px>"+String.format("%.2f",Double.valueOf(money))+"元</font><font size=24px>(扣除手续费"+String.format("%.2f",Double.valueOf(fees))+"元)</font>")); 
	        	withDrawal_record_details_state.setText("失败");
	        	}else if("1".equals(state)){
	        		withDrawal_money_instrution.setVisibility(View.GONE);
	        		BigDecimal b= new BigDecimal(money);
		    		BigDecimal c= new BigDecimal(fees);
	        		withDrawal_record_details_actual_money_layout.setVisibility(View.VISIBLE);
	        		withDrawal_record_details_actual_money.setText(String.format("%.2f", b.subtract(c).doubleValue())+"元");
	         		if(Double.valueOf(fees)==0){
	        			withDrawal_record_details_withdrawlmoney.setText(Html.fromHtml("<font size=28px>"+String.format("%.2f", Double.valueOf(money))+"元</font>")); 
	        		}else{
	        			withDrawal_record_details_withdrawlmoney.setText(Html.fromHtml("<font size=28px>"+String.format("%.2f", Double.valueOf(money))+"元</font><font size=24px>(扣除手续费"+String.format("%.2f", Double.valueOf(fees))+"元)</font>")); 
	        		}
	        		withDrawal_record_details_state.setText("成功");
	        	}else if("3".equals(state)){
	        		if(!instrution.equals("")){
		        		withDrawal_money_instrution.setText("提现申请成功！将"+instrution);}
	        		withDrawal_money_instrution.setVisibility(View.VISIBLE);
	        		withDrawal_record_details_actual_money_layout.setVisibility(View.GONE);
	        		withDrawal_record_details_withdrawlmoney.setText(Html.fromHtml("<font size=28px>"+String.format("%.2f", Double.valueOf(money))+"元</font>"));
	        		withDrawal_record_details_withdrawlmoney.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗
	        		withDrawal_record_details_withdrawlmoney.setTextColor(getResources().getColor(R.color.w_payPass_red));
	        		withDrawal_record_details_state.setText("处理中");
	        	}
	        }
	        withDrawal_record_details_bank_name.setText(bankName);
	        }
	}



	private void initView() {
	
		withDrawal_record_details_bank_name = (TextView) findViewById(R.id.withDrawal_record_details_bank_name);
		withDrawal_record_details_actual_money_layout = (LinearLayout) findViewById(R.id.withDrawal_record_details_actual_money_layout);
		withDrawal_record_details_withdrawlmoney = (TextView) findViewById(R.id.withDrawal_record_details_withdrawlmoney);
		withDrawal_record_details_state = (TextView) findViewById(R.id.withDrawal_record_details_state);
		withDrawal_record_details_back = (TextView) findViewById(R.id.withDrawal_record_details_back);
		withDrawal_money_instrution = (TextView) findViewById(R.id.withDrawal_money_instrution);
		withDrawal_record_details_actual_money = (TextView) findViewById(R.id.withDrawal_record_details_actual_money);
		withDrawal_record_details_back.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int id = v.getId();
		if (id == R.id.withDrawal_record_details_back) {

		finish();
		} else if(id==R.id.wallet_noData){
			 if(NetWorkUtil.getNetWorkInfoType(getApplicationContext())==NetWorkUtil.NONE){
					showToast("请检查网络是否连接！");	
					 loadError(true);
					}else{
						loadError(false);;
					}
		}
	
	}

}
